1. Field of the Invention
This invention relates to a method and apparatus for handling an interrupt from a real-time clock to increment a program clock in a computer system. More particularly, it relates to such a method and apparatus that compensates for time drift due to missed interrupts caused by contention on a system bus from a DMA controller or the like.
2. Description of the Related Art
Computer systems commonly have a real-time clock (RTC), a hardware component that is coupled to a central processing unit (CPU) of the system via a peripheral bus. Usually the RTC and other peripheral devices are coupled to the peripheral bus through an interrupt controller. The RTC is used to update a program clock, typically a date/time clock maintained by the operating system (OS) and referred to herein as the OS clock. Periodically, the RTC generates an interrupt signal on its line to the interrupt controller, which in turn generates a signal on an interrupt line to the CPU as well as a multibit vector on the peripheral bus identifying the RTC as the source of the interrupt. In response to the RTC interrupt, the CPU transfers control to an interrupt handling routine specific to the RTC interrupt, which increments the OS clock, then resumes the previous thread of execution at the point of the interrupt.
Also coupled to the peripheral bus in such systems is a direct memory access (DMA) controller, a hardware component that performs data transfers between memory and peripheral devices without requiring the intermediation of the CPU. To perform such data transfers, the DMA controller negotiates with the CPU to gain control of the peripheral bus as a bus master, to the exclusion of the CPU, for the duration of the DMA transfer.
During such DMA transfers, the RTC is unable to communicate with the CPU, since the CPU does not have control of the peripheral bus. As a result, RTC interrupts will be missed, and the OS clock will gradually lose time relative to the RTC.
The problem has existed since the introduction of Intel-based personal computers in the early 1980s. Others have addressed the problem by periodically resynchronizing the OS clock with the RTC time. This approach, however, has problems of its own. For one, the time drift between resynchronizations accumulates such that the OS time just before any given “resync” with the RTC may be seconds less than the actual time. Then, after resync, the OS time will jump suddenly to the RTC time, which has a one-second resolution. Even if the actual drift of the OS clock is only a fraction of a second, the act of resynchronizing with the RTC will eliminate the fractional portion of the second that the OS keeps track of, because of the one-second resolution of the RTC clock. Moreover, periodically synchronizing the OS clock with the RTC requires CPU cycles, which can detract from other important work.